from classfile.attribute_extra import ExceptionTable
from heap.constant_pool import KlassConstantPool
from heap.system_ref import ClassRef


class ExceptionHandler:

    def __init__(self):
        self.startPc = 0
        self.endPc = 0
        self.handlerPc = 0
        self.catchType: ClassRef = None

    def parse(self, exception_info:ExceptionTable,cp:KlassConstantPool):
        self.startPc = exception_info.getStartPc()
        self.endPc = exception_info.getEndPc()
        self.handlerPc = exception_info.getHandlerPc()
        if exception_info.getCatchType() >0:
            self.catchType = cp.getConstantValue(index=exception_info.getCatchType())


